package Atm01;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * 存款界面
 */
public class SavePanel extends JPanel implements ActionListener {
     private ATMFrame atmFrame;
    private JLabel  inputmoneyLabel = new JLabel("输入存款金额：");
    private JTextField inputmoneyField=new JTextField();
    private JButton sureBtn = new JButton(new ImageIcon("Images/buttonSure.jpg"));

    private Font font = new Font("黑体",Font.BOLD,30);

    public SavePanel(ATMFrame atmFrame){
          this.atmFrame=atmFrame;

        this.setLayout(null);

        inputmoneyLabel.setBounds(200,300,450,50);
        inputmoneyLabel.setText("输入存款金额:");
        inputmoneyLabel.setFont(font);


        inputmoneyField.setBounds(400,300,300,50);
        inputmoneyField.setFont(font);


        sureBtn.setBounds(580,400,150,50);

           this.add(inputmoneyField);
           this.add(inputmoneyLabel);
           this.add(sureBtn);
            sureBtn.addActionListener(this);

          this.setOpaque(false);
    }

    @Override
    public void actionPerformed(ActionEvent e) {


        if (e.getSource() == sureBtn) {
            User user = atmFrame.getLoginUser();
            try{
                user.setBlance(user.getBlance() + Double.parseDouble(inputmoneyField.getText()));
            }catch (NumberFormatException e1){
                JOptionPane.showMessageDialog(this,"必须输入数字");
                return;
            }
            atmFrame.switchPanel("menu");
        }
    }
    }